<template>
    <div class="completion-screen" :style="{ backgroundImage: `url(${bgUrl})` }">
        <div class="blur-overlay"></div>
        
        <main class="completion-content">
            <!-- 标题 -->
            <h1 class="completion-title">{{ title }}</h1>
            
            <!-- 奖励（如果有） -->
            <div class="reward" v-if="reward">{{ reward }}</div>
            
            <!-- Emoji -->
            <div class="emoji">🫰</div>
            
            <!-- 提示文字 -->
            <div class="hint-text" v-if="mode === 'learn'">辨识后拼写,更能加强记忆哦</div>
            
            <!-- 按钮组 -->
            <div class="button-group">
                <button class="primary-btn" @click="startSpelling">强化拼写</button>
                <button class="secondary-btn" @click="showSummary">小结</button>
            </div>
            
            <!-- 复选框 -->
            <div class="checkbox-group">
                <label class="checkbox-label">
                    <input 
                        type="checkbox" 
                        v-model="skipSpelling" 
                        @change="handleSkipChange"
                        class="checkbox-input"
                    />
                    <span class="checkbox-text">{{ mode === 'learn' ? '学习时不再拼写' : '复习时不再拼写' }}</span>
                </label>
            </div>
        </main>
    </div>
</template>

<script setup>
import { ref, computed } from 'vue'
import { useRouter, useRoute } from 'vue-router'
import { bgUrl } from '@/config/background.js'

const router = useRouter()
const route = useRoute()

// 从路由参数获取数据
const mode = ref(route.query.mode || 'learn') // 'learn' 或 'review'
const isFirstGroup = ref(route.query.isFirstGroup === 'true') // 是否是首组
const wordIds = ref(route.query.wordIds ? route.query.wordIds.split(',') : []) // 单词ID列表
const sessionId = ref(route.query.sessionId || '') // 会话ID（用于标识这次学习/复习）

// 计算标题
const title = computed(() => {
    if (mode.value === 'learn') {
        return isFirstGroup.value ? '首组单词学习完成' : '本组单词辨识完成'
    } else {
        return '本组单词辨识完成'
    }
})

// 奖励（学习时显示）
const reward = computed(() => {
    if (mode.value === 'learn') {
        return '+20酷币'
    }
    return null
})

// 跳过拼写设置
const skipSpelling = ref(false)

// 开始拼写
function startSpelling() {
    // 保存跳过拼写设置到localStorage
    if (skipSpelling.value) {
        localStorage.setItem(`${mode.value}_skip_spelling`, 'true')
    }
    
    // 跳转到拼写页面
    router.push({
        path: '/spelling',
        query: {
            mode: mode.value,
            wordIds: wordIds.value.join(','),
            sessionId: sessionId.value
        }
    })
}

// 显示小结
function showSummary() {
    // 保存跳过拼写设置到localStorage
    if (skipSpelling.value) {
        localStorage.setItem(`${mode.value}_skip_spelling`, 'true')
    }
    
    // 跳转到小结页面
    router.push({
        path: '/summary',
        query: {
            mode: mode.value,
            wordIds: wordIds.value.join(','),
            sessionId: sessionId.value
        }
    })
}

// 处理跳过拼写设置变化
function handleSkipChange() {
    // 可以立即保存到localStorage
    if (skipSpelling.value) {
        localStorage.setItem(`${mode.value}_skip_spelling`, 'true')
    } else {
        localStorage.removeItem(`${mode.value}_skip_spelling`)
    }
}
</script>

<style scoped>
.completion-screen {
    position: fixed;
    inset: 0;
    background-position: center;
    background-size: cover;
    background-repeat: no-repeat;
    color: #ffffff;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.blur-overlay {
    position: absolute;
    inset: 0;
    backdrop-filter: blur(35px) brightness(0.95) saturate(1.05);
    -webkit-backdrop-filter: blur(35px) brightness(0.95) saturate(1.05);
    background: rgba(25, 35, 40, 0.25);
    z-index: 0;
}

.completion-content {
    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 24px;
    padding: 40px 20px;
    text-align: center;
}

.completion-title {
    font-size: 24px;
    font-weight: 600;
    color: #ffffff;
    margin: 0;
    letter-spacing: 0.5px;
}

.reward {
    font-size: 20px;
    font-weight: 600;
    color: #fbbf24;
    margin: -8px 0 0 0;
}

.emoji {
    font-size: 80px;
    margin: 8px 0;
    line-height: 1;
}

.hint-text {
    font-size: 14px;
    color: #cbd5e1;
    margin: -8px 0 8px 0;
    line-height: 1.6;
}

.button-group {
    display: flex;
    gap: 16px;
    margin-top: 8px;
}

.primary-btn {
    background: linear-gradient(135deg, #f59e0b 0%, #f97316 100%);
    color: #ffffff;
    border: none;
    border-radius: 12px;
    padding: 14px 32px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 12px rgba(245, 158, 11, 0.3);
}

.primary-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(245, 158, 11, 0.4);
}

.primary-btn:active {
    transform: translateY(0);
}

.secondary-btn {
    background: rgba(255, 255, 255, 0.1);
    color: #ffffff;
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 12px;
    padding: 14px 32px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    backdrop-filter: blur(8px);
}

.secondary-btn:hover {
    background: rgba(255, 255, 255, 0.15);
    border-color: rgba(255, 255, 255, 0.4);
}

.checkbox-group {
    margin-top: 16px;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    user-select: none;
}

.checkbox-input {
    width: 18px;
    height: 18px;
    cursor: pointer;
    accent-color: #fbbf24;
}

.checkbox-text {
    font-size: 14px;
    color: #cbd5e1;
}

.checkbox-label:hover .checkbox-text {
    color: #ffffff;
}
</style>


